extends CharacterBody2D
@onready var animation=$AnimatedSprite2D
var speed:=50
# ----------------------生命周期---------------------------#
func _physics_process(_delta: float) -> void:
	move()
	updateAnimation()

# ----------------------响应函数---------------------------#
# 移动
func move():
	var motion=Input.get_vector('ui_left','ui_right','ui_up','ui_down')
	velocity=motion*speed
	move_and_slide()

# 更新动画
func updateAnimation():
	if velocity.length()==0:animation.stop();return
	var dir='向下'
	if velocity.y<0:dir='向上'
	if velocity.x!=0:
		dir='向左'
		animation.flip_h=velocity.x>0
	animation.play(dir+'走')
